﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes ;
using THSLib;using THSERP.BaseProvider;
namespace THSERP.Modules.UserManagement
{
    public partial class guiAddUserGroups : THSERPScreen
    {
        TreeList TreeList = null;

        public guiAddUserGroups()
        {
            InitializeComponent();
        }
        public guiAddUserGroups(TreeList _treeList)
        {
            InitializeComponent();
            this.TreeList = _treeList;
        }
        private void fld_btnCloseUserGroup_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void fld_btnAddUserGroup_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(fld_txtUserGroup.Text))
            {
                MessageBox.Show("The user group name can not be empty.", "#Message#", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            ADUserGroupsController objUserGroupsController = new ADUserGroupsController();
            ADUserGroupsInfo objADUserGroupsInfo = (ADUserGroupsInfo)objUserGroupsController.GetObjectByID(Convert.ToInt32(TreeList.FocusedNode.Tag));
            if (objADUserGroupsInfo == null)
            {
                objADUserGroupsInfo = new ADUserGroupsInfo();
                objADUserGroupsInfo.ADUserGroupName = fld_txtUserGroup.Text;
                objADUserGroupsInfo.ADLanguageIDCombo = 1;
                objADUserGroupsInfo.ADUserGroupDesc = fld_txtUserGroup.Text;
                objUserGroupsController.CreateObject(objADUserGroupsInfo);
            }
            else
            {
                objADUserGroupsInfo.ADUserGroupName = fld_txtUserGroup.Text;
                objADUserGroupsInfo.ADUserGroupDesc = fld_txtUserGroup.Text;
                objUserGroupsController.UpdateObject(objADUserGroupsInfo);
            }
            ((UserManagementModule)this.Module).InitializeTreeList(TreeList);
            this.Close();
        }
    }
}